import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/controllers/recovery_controller/recovery_page_controller.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/utils/refresh_util.dart';
import 'package:xinxuan/vo/seckill_recovery_vo.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SeckillRecoveryGoodArr extends StatefulWidget {
  final List<SeckillRecoveryItem> seckillRecoveryItems;
  final RecoveryPageController recoveryPageController;
  SeckillRecoveryGoodArr({
    required this.seckillRecoveryItems,
    required this.recoveryPageController
  });
  @override
  _SeckillRecoveryGoodArrState createState() => _SeckillRecoveryGoodArrState();
}

class _SeckillRecoveryGoodArrState extends State<SeckillRecoveryGoodArr> with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    if ( widget.seckillRecoveryItems.length <= 0) {
      return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.asset(
              'assets/icons/icon_recovery_def.png',
              width: 254.w,
              height: 133.h,
            ),
            SizedBox(height: 10.h),
            Text(
              '暂时没有可以回收的商品哦~',
              style: TextStyle(
                color: textSubtitleColor,
                fontSize: 14.sp
              ),
            )
          ],
        ),
      );
    }
    return RefreshUtil.easyRefresh(
      // onRefresh: () async {
        // widget.seckillOrderPageController.getSeckillTabItemOrderList(widget.seckillOrderPageController.tabIndex.value);
      // },
      onLoad: () async {
        widget.recoveryPageController.onloadSeckillRecoveryList();
      },
      slivers: [
        SliverToBoxAdapter(
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 16.w),
            margin: EdgeInsets.only(top: 12.h),
            child: StaggeredGridView.countBuilder(
              padding: EdgeInsets.zero,
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              crossAxisCount: 4,
              itemCount: widget.seckillRecoveryItems.length,
              staggeredTileBuilder: (int index) => StaggeredTile.fit(2),
              mainAxisSpacing: 12.h,
              crossAxisSpacing: 13.w,
              itemBuilder: (BuildContext context, int index) {
                SeckillRecoveryItem item = widget.seckillRecoveryItems[index];
                return Container(
                  width: 165.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(5.w),
                    color: bgWhiteColor
                  ),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      NetworkImageUtil(
                        url: item.image ?? '', 
                        width: 165.w, 
                        height: 165.w,
                        topRightRadius: 5.w,
                        topLeftRadius: 5.w,
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 12.h),
                        padding: EdgeInsets.symmetric(horizontal: 6.w),
                        child: Column(
                          children: [
                            Text(
                              '${item.title}',
                              overflow: TextOverflow.ellipsis,
                              maxLines: 2,
                              style: TextStyle(
                                color: textBlackColor,
                                fontSize: 14.sp,
                                fontWeight: FontWeight.bold
                              ),
                            ),
                            SizedBox(height: 6.h),
                            Row(
                              children: [
                                Expanded(child: Text.rich(
                                  TextSpan(
                                    text: '¥',
                                    style: TextStyle(
                                      color: mainTextColor,
                                      fontSize: 12.sp,
                                      fontWeight: FontWeight.bold
                                    ),
                                    children: [
                                      TextSpan(
                                        text: '${item.price}',
                                        style: TextStyle(
                                          color: mainTextColor,
                                          fontSize: 16.sp,
                                          fontWeight: FontWeight.bold
                                        )
                                      )
                                    ]
                                  )
                                )),
                                Container(
                                  padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 2.h),
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(3.w),
                                    color: bgRecoveryStatus
                                  ),
                                  child: Text(
                                    '${item.statusStr}',
                                    style: TextStyle(
                                      color: mainTextColor,
                                      fontSize: 12.sp
                                    ),
                                  ),
                                )
                              ],
                            )
                          ],
                        ),
                      ),
                      SizedBox(height: 12.h)
                    ],
                  ),
                );
              },
            ),
          ),
        )
      ]
    );
  }

  @override
  bool get wantKeepAlive => true;
}